<?php echo $this->Html->css('web/org_subscription.css'); ?>
<?php //debug($this->Session->read('signup_info')); ?>

<?php echo $this->element('organisation/web/register_steps', array('active' => 'review')); ?>

<div class='form-actions well-small'>
    <h4>Subscription Registration Review</h4>
    <p>Please review the information provided below and complete your registration</p>
</div>

<form class='form form-horizontal' method='post' action='<?php echo $this->Html->url(array('action' => 'register')); ?>'>
    <div class='well well-small'>
        <b class='pull-left'>Subscription Type</b>

        <a href='<?php echo $this->Html->url(array('action' => 'register_subscription')); ?>' class='btn btn-mini btn-info pull-right'><i class='icon icon-edit'></i> Edit</a>
    </div>

    <table class='table table-condensed'>
        <tr>
            <td style='width: 180px;'>Subscription Type:</td>
            <td><?php echo strtoupper($signup_info['SubscriptionType']['name']); ?></td>
        </tr>
        <tr>
            <td>Subscription Cost:</td>
            <td><?php echo 'GHC ' . strtoupper($signup_info['SubscriptionType']['initial_price']); ?></td>
        </tr>
        <tr>
            <td>Subscription Start:</td>
            <td><?php echo date('d M Y', strtotime($signup_info['Organisation']['OrganisationSubscription'][0]['start_dt']) ); ?></td>
        </tr>
        
        <tr>
            <td>Subscription End:</td>
            <td><?php echo date('d M Y', strtotime($signup_info['Organisation']['OrganisationSubscription'][0]['end_dt'])); ?></td>
        </tr>
    </table>
    
    <div class='well well-small'>
        <b>Organisation Info</b>

        <a href='<?php echo $this->Html->url(array('action' => 'register_info')); ?>' class='btn btn-mini btn-info pull-right'><i class='icon icon-edit'></i> Edit</a>
    </div>
    
    <table class='table table-condensed'>
        <tr>
            <td style='width: 180px;'>Organisation Name:</td>
            <td><?php echo $signup_info['Organisation']['Organisation']['name']; ?></td>
        </tr>
        <tr>
            <td>Organisation Type:</td>
            <td><?php echo $signup_info['Organisation']['OrganisationType']['name']; ?></td>
        </tr>
        
        <tr>
            <td>Primary Account Name:</td>
            <td><?php echo $signup_info['Organisation']['OrganisationAccount'][0]['first_name'] . ' ' . $signup_info['Organisation']['OrganisationAccount'][0]['last_name']; ?></td>
        </tr>
        
        <tr>
            <td>Account Username:</td>
            <td><?php echo $signup_info['Organisation']['OrganisationAccount'][0]['username']; ?></td>
        </tr>
        
    </table>

    <?php if( isset($signup_info['Billing'])) { ?>
    <div class='well well-small'>
        <b>Billing Information</b>

        <a href='<?php echo $this->Html->url(array('action' => 'register_payments')); ?>' class='btn btn-mini btn-info pull-right'><i class='icon icon-edit'></i> Edit</a>
    </div>
    
    <table class='table table-condensed'>
        <tr>
            <td style='width: 180px;'>Billing Name:</td>
            <td><?php echo $signup_info['Billing']['first_name'] . ' ' . $signup_info['Billing']['last_name']; ?></td>
        </tr>
        <tr>
            <td>Card Number:</td>
            <td>
                <?php 
                $card_number = $signup_info['Billing']['card_number'];
                echo str_replace(substr($card_number, 0, strlen($card_number) - 4), 'VISA-', $card_number); 
                ?>
            </td>
        </tr>
        
        <tr>
            <td>Expiry Month / Year:</td>
            <td><?php echo $signup_info['Billing']['expiry_month'] . ' / ' . $signup_info['Billing']['expiry_year']; ?></td>
        </tr>
        
    </table>
    <?php } ?>

    <table class="table">
        <tr>
            <td width="150"></td>
            <td style='padding-top: 30px'>
                <label style="font-size: 12px;" >
                    <input type="checkbox" value="1" name="data[agreed_to_terms]" id="agreed_to_terms" />
                    
                    I agree to the "<a id="register_terms" href="<?php echo $this->Html->url(array('action' => 'register_terms')); ?>">Terms & Conditions</a>" for using this service.
                </label>
                
            </td>
        </tr>
    </table>
    
    <div class='form-actions'>
        <button class='btn btn-success' type='submit' disabled="" id="complete_register">Complete Registration</button>
        <a href='<?php echo $this->Html->url(array('action' => 'register_cancel')); ?>' class='btn btn-cancel'>Cancel</a>
    </div>
</form>

<script>
$(document).ready(function() {
    $("#agreed_to_terms").change(function() {
  
        if( $(this).is(":checked") ) {
            $("#complete_register").removeAttr('disabled');
        }
        
        else {
            $("#complete_register").attr('disabled', 'disabled');
        }
    });
    
    $("#register_terms").click(function(e) {
        e.preventDefault();
        
        $.get( $(this).attr('href'), function(html) {
            var dialog = $("<div />").dialog({
                title: 'Terms And Conditions',
                width: 700,
                height: 500,
                modal: true,
                buttons: {
                    'Close': function() {
                        dialog.dialog('close');
                    }
                }
            }).html(html);
            
        });
    });
});
</script>